namespace SmartSoft.Controls
{
    using SmartSoft;
    using SmartSoft.Properties;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormListEditor : FormControl
    {
        private ToolStripButton btnAdd;
        private ToolStripButton btnCancel;
        private ToolStripButton btnClose;
        private ToolStripButton btnDelete;
        private ToolStripButton btnEdit;
        private ToolStripButton btnSave;
        private IContainer components;
        private bool ib_NewChecked;
        private bool ib_ShowAddButton;
        private bool ib_ShowDeleteButton;
        private bool ib_ShowEditButton;
        private bool ib_ShowFreeFields;
        private bool ib_ShowSaveButton;
        private string is_AddTitleText;
        private string is_EditTitleText;
        private string is_FirstFreeCode;
        private string is_SecondFreeCode;
        private string is_ThirdFreeCode;
        public LabelControl lblPhan_Loai;
        private DataRow oCurrentRow;
        private DataTable oDataTable;
        private FormListLister oLocalFormLister;
        private object oUserDefined1;
        private object oUserDefined2;
        private object oUserDefined3;
        private object oUserDefined4;
        private ToolStripSeparator tbrSep01;
        private ToolStripSeparator tbrSep02;
        private ToolStripSeparator tbrSep03;
        private ToolStrip Toolbars;
        public TextSearch txtMa_Loai1;
        public TextSearch txtMa_Loai2;
        protected ErrorProvider errorProvider;
        private ToolStripSeparator toolStripSeparator1;
        protected ToolStripTextBox txtExcelPath;
        protected ToolStripButton btnBrowser;
        private ToolStripSeparator toolStripSeparator2;
        protected ToolStripButton btnImporter;
        private OpenFileDialog openFileDialog1;
        public TextSearch txtMa_Loai3;

        public FormListEditor()
        {
            this.ib_ShowAddButton = true;
            this.ib_ShowSaveButton = true;
            this.ib_ShowFreeFields = true;
            this.InitializeComponent();
        }

        public FormListEditor(object poUserDefined1, object poUserDefined2)
        {
            this.ib_ShowAddButton = true;
            this.ib_ShowSaveButton = true;
            this.ib_ShowFreeFields = true;
            this.InitializeComponent();
            this.UserDefined1 = poUserDefined1;
            this.UserDefined2 = poUserDefined2;
        }

        public FormListEditor(object poUserDefined1, object poUserDefined2, object poUserDefined3)
        {
            this.ib_ShowAddButton = true;
            this.ib_ShowSaveButton = true;
            this.ib_ShowFreeFields = true;
            this.InitializeComponent();
            this.UserDefined1 = poUserDefined1;
            this.UserDefined2 = poUserDefined2;
            this.UserDefined3 = poUserDefined3;
        }

        public FormListEditor(object poUserDefined1, object poUserDefined2, object poUserDefined3, object poUserDefined4)
        {
            this.ib_ShowAddButton = true;
            this.ib_ShowSaveButton = true;
            this.ib_ShowFreeFields = true;
            this.InitializeComponent();
            this.UserDefined1 = poUserDefined1;
            this.UserDefined2 = poUserDefined2;
            this.UserDefined3 = poUserDefined3;
            this.UserDefined4 = poUserDefined4;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (this.OnSave())
            {
                if (!this.AllowAddItem)
                {
                    this.NewChecked = false;
                    MessageBox.Show("Không có quyền th\x00eam mới danh mục!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else
                {
                    this.NewChecked = true;
                    this.OnReset();
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.OnCancel();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            this.OnDelete();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            this.OnEdit();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.OnSave() && !this.ShowEditButton)
            {
                base.Close();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private string GetTitleMessage()
        {
            if (!this.NewChecked)
            {
                return this.EditTitleText;
            }
            return this.AddTitleText;
        }

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.Toolbars = new System.Windows.Forms.ToolStrip();
            this.btnAdd = new System.Windows.Forms.ToolStripButton();
            this.btnEdit = new System.Windows.Forms.ToolStripButton();
            this.btnDelete = new System.Windows.Forms.ToolStripButton();
            this.tbrSep01 = new System.Windows.Forms.ToolStripSeparator();
            this.btnSave = new System.Windows.Forms.ToolStripButton();
            this.tbrSep02 = new System.Windows.Forms.ToolStripSeparator();
            this.btnCancel = new System.Windows.Forms.ToolStripButton();
            this.tbrSep03 = new System.Windows.Forms.ToolStripSeparator();
            this.btnClose = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.txtExcelPath = new System.Windows.Forms.ToolStripTextBox();
            this.btnBrowser = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
            this.btnImporter = new System.Windows.Forms.ToolStripButton();
            this.txtMa_Loai3 = new SmartSoft.Controls.TextSearch();
            this.txtMa_Loai2 = new SmartSoft.Controls.TextSearch();
            this.txtMa_Loai1 = new SmartSoft.Controls.TextSearch();
            this.lblPhan_Loai = new SmartSoft.Controls.LabelControl();
            this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.Toolbars.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
            this.SuspendLayout();
            // 
            // Toolbars
            // 
            this.Toolbars.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.btnAdd,
            this.btnEdit,
            this.btnDelete,
            this.tbrSep01,
            this.btnSave,
            this.tbrSep02,
            this.btnCancel,
            this.tbrSep03,
            this.btnClose,
            this.toolStripSeparator1,
            this.txtExcelPath,
            this.btnBrowser,
            this.toolStripSeparator2,
            this.btnImporter});
            this.Toolbars.Location = new System.Drawing.Point(0, 0);
            this.Toolbars.Name = "Toolbars";
            this.Toolbars.Size = new System.Drawing.Size(766, 25);
            this.Toolbars.TabIndex = 0;
            this.Toolbars.Text = "Toolbars";
            // 
            // btnAdd
            // 
            this.btnAdd.Image = global::SmartSoft.Properties.Resources.BALANCE1;
            this.btnAdd.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new System.Drawing.Size(58, 22);
            this.btnAdd.Text = "Thêm";
            this.btnAdd.ToolTipText = "Thêm mới (F2)";
            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
            // 
            // btnEdit
            // 
            this.btnEdit.Image = global::SmartSoft.Properties.Resources.EDIT1;
            this.btnEdit.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnEdit.Name = "btnEdit";
            this.btnEdit.Size = new System.Drawing.Size(46, 22);
            this.btnEdit.Text = "Sửa";
            this.btnEdit.ToolTipText = "Sửa (F3)";
            this.btnEdit.Visible = false;
            this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click);
            // 
            // btnDelete
            // 
            this.btnDelete.Image = global::SmartSoft.Properties.Resources.DELETE1;
            this.btnDelete.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnDelete.Name = "btnDelete";
            this.btnDelete.Size = new System.Drawing.Size(47, 22);
            this.btnDelete.Text = "Xóa";
            this.btnDelete.ToolTipText = "Xóa (F8)";
            this.btnDelete.Visible = false;
            this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
            // 
            // tbrSep01
            // 
            this.tbrSep01.Name = "tbrSep01";
            this.tbrSep01.Size = new System.Drawing.Size(6, 25);
            // 
            // btnSave
            // 
            this.btnSave.Image = global::SmartSoft.Properties.Resources.SAVE1;
            this.btnSave.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(47, 22);
            this.btnSave.Text = "Lưu";
            this.btnSave.ToolTipText = "Ghi lại và Thoát (Ctrl+Enter)";
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // tbrSep02
            // 
            this.tbrSep02.Name = "tbrSep02";
            this.tbrSep02.Size = new System.Drawing.Size(6, 25);
            // 
            // btnCancel
            // 
            this.btnCancel.Image = global::SmartSoft.Properties.Resources.CANCEL;
            this.btnCancel.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(77, 22);
            this.btnCancel.Text = "Huỷ (Esc)";
            this.btnCancel.ToolTipText = "Huỷ (Esc)";
            this.btnCancel.Visible = false;
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // tbrSep03
            // 
            this.tbrSep03.Name = "tbrSep03";
            this.tbrSep03.Size = new System.Drawing.Size(6, 25);
            this.tbrSep03.Visible = false;
            // 
            // btnClose
            // 
            this.btnClose.Image = global::SmartSoft.Properties.Resources.CLOSE;
            this.btnClose.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new System.Drawing.Size(58, 22);
            this.btnClose.Text = "Thoát";
            this.btnClose.ToolTipText = "Thoát (Esc)";
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // toolStripSeparator1
            // 
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
            this.toolStripSeparator1.Visible = false;
            // 
            // txtExcelPath
            // 
            this.txtExcelPath.Name = "txtExcelPath";
            this.txtExcelPath.ReadOnly = true;
            this.txtExcelPath.Size = new System.Drawing.Size(400, 25);
            this.txtExcelPath.Visible = false;
            // 
            // btnBrowser
            // 
            this.btnBrowser.Image = global::SmartSoft.Properties.Resources.PREVIEW;
            this.btnBrowser.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnBrowser.Name = "btnBrowser";
            this.btnBrowser.Size = new System.Drawing.Size(75, 22);
            this.btnBrowser.Text = "Chọn file";
            this.btnBrowser.Visible = false;
            this.btnBrowser.Click += new System.EventHandler(this.btnBrowser_Click);
            // 
            // toolStripSeparator2
            // 
            this.toolStripSeparator2.Name = "toolStripSeparator2";
            this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
            this.toolStripSeparator2.Visible = false;
            // 
            // btnImporter
            // 
            this.btnImporter.Image = global::SmartSoft.Properties.Resources.DETAIL;
            this.btnImporter.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnImporter.Name = "btnImporter";
            this.btnImporter.Size = new System.Drawing.Size(88, 22);
            this.btnImporter.Text = "Chuyển đổi";
            this.btnImporter.Visible = false;
            this.btnImporter.Click += new System.EventHandler(this.btnImporter_Click);
            // 
            // txtMa_Loai3
            // 
            this.txtMa_Loai3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.txtMa_Loai3.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Loai3.CheckTextSearched = false;
            this.txtMa_Loai3.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Loai3.EmptyIsValid = true;
            this.txtMa_Loai3.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Loai3.Location = new System.Drawing.Point(379, 149);
            this.txtMa_Loai3.MaxLength = 32;
            this.txtMa_Loai3.Name = "txtMa_Loai3";
            this.txtMa_Loai3.OldValue = null;
            this.txtMa_Loai3.Size = new System.Drawing.Size(126, 20);
            this.txtMa_Loai3.TabIndex = 38;
            this.txtMa_Loai3.TableName = "DMLOAI";
            this.txtMa_Loai3.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Loai3.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Loai3.Value = global::SmartSoft.ReportForms.FormVTH02BViewer.txtTen_Nh_Vt_Value;
            // 
            // txtMa_Loai2
            // 
            this.txtMa_Loai2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.txtMa_Loai2.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Loai2.CheckTextSearched = false;
            this.txtMa_Loai2.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Loai2.EmptyIsValid = true;
            this.txtMa_Loai2.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Loai2.Location = new System.Drawing.Point(251, 149);
            this.txtMa_Loai2.MaxLength = 32;
            this.txtMa_Loai2.Name = "txtMa_Loai2";
            this.txtMa_Loai2.OldValue = null;
            this.txtMa_Loai2.Size = new System.Drawing.Size(126, 20);
            this.txtMa_Loai2.TabIndex = 37;
            this.txtMa_Loai2.TableName = "DMLOAI";
            this.txtMa_Loai2.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Loai2.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Loai2.Value = global::SmartSoft.ReportForms.FormVTH02BViewer.txtTen_Nh_Vt_Value;
            // 
            // txtMa_Loai1
            // 
            this.txtMa_Loai1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.txtMa_Loai1.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Loai1.CheckTextSearched = false;
            this.txtMa_Loai1.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Loai1.EmptyIsValid = true;
            this.txtMa_Loai1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Loai1.Location = new System.Drawing.Point(123, 149);
            this.txtMa_Loai1.MaxLength = 32;
            this.txtMa_Loai1.Name = "txtMa_Loai1";
            this.txtMa_Loai1.OldValue = null;
            this.txtMa_Loai1.Size = new System.Drawing.Size(126, 20);
            this.txtMa_Loai1.TabIndex = 36;
            this.txtMa_Loai1.TableName = "DMLOAI";
            this.txtMa_Loai1.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Loai1.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Loai1.Value = global::SmartSoft.ReportForms.FormVTH02BViewer.txtTen_Nh_Vt_Value;
            // 
            // lblPhan_Loai
            // 
            this.lblPhan_Loai.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.lblPhan_Loai.AutoSize = true;
            this.lblPhan_Loai.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblPhan_Loai.Location = new System.Drawing.Point(12, 152);
            this.lblPhan_Loai.Name = "lblPhan_Loai";
            this.lblPhan_Loai.Size = new System.Drawing.Size(50, 14);
            this.lblPhan_Loai.TabIndex = 35;
            this.lblPhan_Loai.Text = "Phân loại";
            // 
            // errorProvider
            // 
            this.errorProvider.ContainerControl = this;
            // 
            // openFileDialog1
            // 
            this.openFileDialog1.FileName = "openFileDialog1";
            // 
            // FormListEditor
            // 
            this.ClientSize = new System.Drawing.Size(766, 183);
            this.Controls.Add(this.txtMa_Loai3);
            this.Controls.Add(this.txtMa_Loai2);
            this.Controls.Add(this.txtMa_Loai1);
            this.Controls.Add(this.lblPhan_Loai);
            this.Controls.Add(this.Toolbars);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FormListEditor";
            this.Toolbars.ResumeLayout(false);
            this.Toolbars.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected virtual void OnAdd()
        {
            this.NewChecked = true;
            this.OnResetStatus(false);
        }

        protected virtual void OnCancel()
        {
            this.OnResetStatus(true);
        }

        protected virtual void OnDelete()
        {
        }

        protected virtual void OnEdit()
        {
            this.OnResetStatus(false);
        }

        protected virtual void OnReset()
        {
        }

        protected virtual void OnResetStatus(bool pb_Status)
        {
            this.btnAdd.Enabled = pb_Status;
            this.btnEdit.Enabled = pb_Status;
            this.btnDelete.Enabled = pb_Status;
            this.btnSave.Enabled = !pb_Status;
            this.btnCancel.Enabled = !pb_Status;
        }

        public virtual bool OnSave()
        {
            if (this.ShowSaveButton)
            {
                if (this.ShowEditButton)
                {
                    this.OnResetStatus(true);
                }
                if (this.RefreshAfterChanged)
                {
                    this.LocalFormLister.OnRefresh();
                }
                if (!this.OrderFieldNames.Equals(string.Empty))
                {
                    ((BindingSource) this.LocalGridBrowser.DataSource).Sort = this.OrderFieldNames;
                }
                if (this.LocalFormLister != null)
                {
                    this.LocalFormLister.OnSetPosition(this.LocalFieldName, this.LocalCurrentRow[this.LocalFieldName]);
                }
            }
            return true;
        }

        public virtual void OnShow()
        {
            //SendKeys.Send("{End}");
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
                case Keys.F8:
                    if (this.ShowDeleteButton && this.btnDelete.Enabled)
                    {
                        this.OnDelete();
                    }
                    return true;

                case (Keys.Control | Keys.Return):
                    if (((base.ActiveControl is IDataGridViewEditingControl) && (base.ActiveControl.Parent != null)) && ((base.ActiveControl.Parent.Parent != null) && (base.ActiveControl.Parent.Parent is DataGridView)))
                    {
                        (base.ActiveControl.Parent.Parent as DataGridView).EndEdit();
                    }
                    if ((this.btnSave.Enabled && this.OnSave()) && !this.ShowEditButton)
                    {
                        base.Close();
                    }
                    return true;

                case Keys.F2:
                    if ((this.ShowAddButton && this.OnSave()) && this.btnAdd.Enabled)
                    {
                        if (this.ShowEditButton)
                        {
                            this.OnAdd();
                            break;
                        }
                        if (this.AllowAddItem)
                        {
                            this.NewChecked = true;
                            this.OnReset();
                            break;
                        }
                        this.NewChecked = false;
                        MessageBox.Show("Không có quyền th\x00eam mới danh mục!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    break;

                case Keys.F3:
                    if (this.ShowEditButton)
                    {
                        if (!this.btnEdit.Enabled)
                        {
                            if (this.btnSave.Enabled)
                            {
                                if (((base.ActiveControl is IDataGridViewEditingControl) && (base.ActiveControl.Parent != null)) && ((base.ActiveControl.Parent.Parent != null) && (base.ActiveControl.Parent.Parent is DataGridView)))
                                {
                                    (base.ActiveControl.Parent.Parent as DataGridView).EndEdit();
                                }
                                this.OnSave();
                            }
                        }
                        else
                        {
                            this.OnEdit();
                        }
                    }
                    return true;

                case Keys.Escape:
                    if (this.ShowEditButton && this.btnCancel.Enabled)
                    {
                        this.OnCancel();
                    }
                    else
                    {
                        base.Close();
                    }
                    return true;

                default:
                    return base.ProcessCmdKey(ref msg, keyData);
            }
            return true;
        }

        private void SetFreeColumns()
        {
            if (this.ShowFreeFields && (this.LocalFieldCount < 1))
            {
                this.lblPhan_Loai.Visible = false;
                this.txtMa_Loai1.Visible = false;
                this.txtMa_Loai2.Visible = false;
                this.txtMa_Loai3.Visible = false;
                if (this.MinimumSize.Height > ((base.Height - this.txtMa_Loai1.Height) - 3))
                {
                    this.MinimumSize = new Size(this.MinimumSize.Width, (base.Height - this.txtMa_Loai1.Height) - 3);
                }
                base.Height = (base.Height - this.txtMa_Loai1.Height) - 3;
            }
        }

        public bool ShowMessage(DataRow row, int pi_Result)
        {
            switch (pi_Result)
            {
                case -3:
                    row.RejectChanges();
                    MessageBox.Show("Mã lồng nhau!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return true;

                case -1:
                    row.RejectChanges();
                    MessageBox.Show("Mã đã tồn tại!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return true;
            }
            return false;
        }

        [DefaultValue(""), Category("Editor properties"), Description("The title text when adding.")]
        public string AddTitleText
        {
            get
            {
                return this.is_AddTitleText;
            }
            set
            {
                this.is_AddTitleText = value;
                this.Text = value;
            }
        }

        [Browsable(false), DefaultValue(false), Category("Editor properties"), Description("Allow this user add new item.")]
        public bool AllowAddItem
        {
            get
            {
                return ((this.LocalFormLister != null) && this.LocalFormLister.AllowAddItem);
            }
        }

        [Description("The title text when editing."), DefaultValue(""), Category("Editor properties")]
        public string EditTitleText
        {
            get
            {
                return this.is_EditTitleText;
            }
            set
            {
                this.is_EditTitleText = value;
            }
        }

        [Category("Editor properties"), Description("Get or set the first free code.")]
        public string FirstFreeCode
        {
            get
            {
                return this.is_FirstFreeCode;
            }
            set
            {
                this.is_FirstFreeCode = value;
                this.txtMa_Loai1.FirstFilter = "Type = '" + this.is_FirstFreeCode + "'";
            }
        }

        [Browsable(false)]
        public DataRow LocalCurrentRow
        {
            get
            {
                return this.oCurrentRow;
            }
            set
            {
                this.oCurrentRow = value;
                if ((this.oCurrentRow != null) && (this.oCurrentRow.RowState == DataRowState.Unchanged))
                {
                    this.OnShow();
                }
                this.OnReset();
            }
        }

        [Browsable(false)]
        private int LocalFieldCount
        {
            get
            {
                if (this.LocalFormLister != null)
                {
                    return this.LocalFormLister.LocalFieldCount;
                }
                return 0;
            }
        }

        [Browsable(false)]
        protected string LocalFieldName
        {
            get
            {
                if (this.LocalFormLister != null)
                {
                    return this.LocalFormLister.LocalFieldName;
                }
                return string.Empty;
            }
        }

        [Browsable(false)]
        public FormListLister LocalFormLister
        {
            get
            {
                return this.oLocalFormLister;
            }
            set
            {
                this.oLocalFormLister = value;
                this.SetFreeColumns();
            }
        }

        [Browsable(false)]
        private DataGridView LocalGridBrowser
        {
            get
            {
                if (this.LocalFormLister != null)
                {
                    return this.LocalFormLister.LocalGridBrowser;
                }
                return null;
            }
        }

        [Browsable(false)]
        public DataTable LocalTable
        {
            get
            {
                if (this.oDataTable != null)
                {
                    return this.oDataTable;
                }
                if ((this.LocalFormLister != null) && (this.LocalFormLister.LocalTable != null))
                {
                    return this.LocalFormLister.LocalTable;
                }
                return null;
            }
            set
            {
                this.oDataTable = value;
            }
        }

        [Browsable(false)]
        public bool NewChecked
        {
            get
            {
                return this.ib_NewChecked;
            }
            set
            {
                this.ib_NewChecked = value;
                this.Text = this.GetTitleMessage();
            }
        }

        [Browsable(false)]
        private string OrderFieldNames
        {
            get
            {
                if (this.LocalFormLister != null)
                {
                    return this.LocalFormLister.OrderFieldNames;
                }
                return string.Empty;
            }
        }

        [Browsable(false)]
        private bool RefreshAfterChanged
        {
            get
            {
                return ((this.LocalFormLister != null) && this.LocalFormLister.RefreshAfterChanged);
            }
        }

        [Description("Get or set the second free code."), Category("Editor properties")]
        public string SecondFreeCode
        {
            get
            {
                return this.is_SecondFreeCode;
            }
            set
            {
                this.is_SecondFreeCode = value;
                this.txtMa_Loai2.FirstFilter = "Type = '" + this.is_SecondFreeCode + "'";
            }
        }

        [DefaultValue(true), Category("Editor properties"), Description("Whether show the add button or hide.")]
        public bool ShowAddButton
        {
            get
            {
                return this.ib_ShowAddButton;
            }
            set
            {
                if (this.ib_ShowAddButton != value)
                {
                    this.ib_ShowAddButton = value;
                    this.btnAdd.Visible = this.ShowAddButton;
                    this.tbrSep01.Visible = (this.ShowAddButton || this.ShowEditButton) || this.ShowDeleteButton;
                }
            }
        }

        [Description("Whether show the delete button or hide."), DefaultValue(false), Category("Editor properties")]
        public bool ShowDeleteButton
        {
            get
            {
                return this.ib_ShowDeleteButton;
            }
            set
            {
                if (this.ib_ShowDeleteButton != value)
                {
                    this.ib_ShowDeleteButton = value;
                    this.btnDelete.Visible = this.ShowDeleteButton;
                    this.tbrSep01.Visible = (this.ShowAddButton || this.ShowEditButton) || this.ShowDeleteButton;
                }
            }
        }

        [Description("Whether show the edit button or hide."), DefaultValue(false), Category("Editor properties")]
        public bool ShowEditButton
        {
            get
            {
                return this.ib_ShowEditButton;
            }
            set
            {
                if (this.ib_ShowEditButton != value)
                {
                    this.ib_ShowEditButton = value;
                    this.btnEdit.Visible = this.ShowEditButton;
                    this.tbrSep01.Visible = (this.ShowAddButton || this.ShowEditButton) || this.ShowDeleteButton;
                    this.btnCancel.Visible = this.ShowEditButton;
                    this.tbrSep03.Visible = this.ShowEditButton;
                }
                if (this.ShowEditButton)
                {
                    this.OnResetStatus(this.ShowEditButton);
                }
                else
                {
                    this.btnSave.Enabled = true;
                }
            }
        }

        [DefaultValue(true), Category("Editor properties"), Description("Whether show the free fields or hide.")]
        public bool ShowFreeFields
        {
            get
            {
                if ((this.LocalFormLister != null) && (this.LocalFormLister != null))
                {
                    return this.LocalFormLister.ShowFreeFields;
                }
                return this.ib_ShowFreeFields;
            }
            set
            {
                if (this.ib_ShowFreeFields != value)
                {
                    this.ib_ShowFreeFields = value;
                    this.lblPhan_Loai.Visible = this.ShowFreeFields;
                    this.txtMa_Loai1.Visible = this.ShowFreeFields;
                    this.txtMa_Loai2.Visible = this.ShowFreeFields;
                    this.txtMa_Loai3.Visible = this.ShowFreeFields;
                }
            }
        }

        [DefaultValue(true), Description("Whether show the save button or hide."), Category("Editor properties")]
        public bool ShowSaveButton
        {
            get
            {
                return this.ib_ShowSaveButton;
            }
            set
            {
                if (this.ib_ShowSaveButton != value)
                {
                    this.ib_ShowSaveButton = value;
                    this.btnSave.Visible = this.ShowSaveButton;
                    this.tbrSep02.Visible = this.ShowSaveButton;
                }
            }
        }

        [Description("Get or set the third free code."), Category("Editor properties")]
        public string ThirdFreeCode
        {
            get
            {
                return this.is_ThirdFreeCode;
            }
            set
            {
                this.is_ThirdFreeCode = value;
                this.txtMa_Loai3.FirstFilter = "Type = '" + this.is_ThirdFreeCode + "'";
            }
        }

        public object UserDefined1
        {
            get
            {
                return this.oUserDefined1;
            }
            set
            {
                this.oUserDefined1 = value;
            }
        }

        public object UserDefined2
        {
            get
            {
                return this.oUserDefined2;
            }
            set
            {
                this.oUserDefined2 = value;
            }
        }

        public object UserDefined3
        {
            get
            {
                return this.oUserDefined3;
            }
            set
            {
                this.oUserDefined3 = value;
            }
        }

        public object UserDefined4
        {
            get
            {
                return this.oUserDefined4;
            }
            set
            {
                this.oUserDefined4 = value;
            }
        }        

        private void btnBrowser_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Excel (*.xls;*xlsx)|*.xls;*xlsx|All files (*.*)|*.*";
            openFileDialog1.Title = "Choose a file excel";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                txtExcelPath.Text = openFileDialog1.FileName;
            }
        }

        protected virtual void DoImport()
        {

        }

        protected virtual void ShowImportButtons()
        {
            toolStripSeparator1.Visible = true;
            toolStripSeparator2.Visible = true;
            txtExcelPath.Visible = true;            
            btnBrowser.Visible = true;
            btnImporter.Visible = true;
            //Hide all other control
        }

        private void btnImporter_Click(object sender, EventArgs e)
        {
            DoImport();
        }
    }
}

